package com.design.state.vending;

class VendingMachine {
    private VendingMachineState currentState;

    public VendingMachine() {
        currentState = new EmptyState();
    }

    public void setCurrentState(VendingMachineState state) {
        currentState = state;
    }

    public void insertCoin() {
        currentState.insertCoin();
        if (currentState instanceof EmptyState) {
            setCurrentState(new EmptyState());
        } else {
            setCurrentState(new InsertCoinState());
        }
    }

    public void dispense() {
        currentState.dispense();
    }
}
